import { Transform, Type } from 'class-transformer';
import {
  ArrayNotEmpty,
  IsArray,
  IsIn,
  IsInt,
  IsNotEmpty,
  IsOptional,
} from 'class-validator';

/**
 * 新增字典类型
 * */
export class createData {
  @IsNotEmpty({ message: 'dictName 不能为空' })
  readonly dictName?: string;

  @IsNotEmpty({ message: 'dictType 不能为空' })
  readonly dictType?: string;

  @IsOptional()
  @Type(() => Number)
  @IsIn([0, 1, true, false], { message: 'status 只能是 0 或 1' })
  readonly status?: boolean;

  @IsOptional()
  readonly remark?: string;
}
/**
 * 修改字典类型
 * */
export class updateData {
  @IsNotEmpty({ message: 'dictId 不能为空' })
  @Type(() => Number)
  readonly dictId: number;

  @IsNotEmpty({ message: 'dictName 不能为空' })
  readonly dictName: string;

  @IsOptional({ message: 'dictType不能为空' })
  readonly dictType: string;

  @IsNotEmpty({ message: 'status 不能为空' })
  @Type(() => Number)
  @IsIn([0, 1, true, false], { message: 'status 只能是 0 或 1' })
  readonly status: boolean;

  @IsOptional()
  readonly remark?: string;
}
/**
 * 查询字典类型列表
 * */
export class getList {
  @IsOptional()
  @Type(() => Number)
  readonly pageNum?: number = 1;

  @IsOptional()
  @Type(() => Number)
  readonly pageSize?: number = 10;
}
/**
 * 删除字典类型
 * */
export class deleteType {
  @IsNotEmpty({ message: 'dictIds 必填' })
  @Transform(({ value }) => value.split(',').map(Number), { toClassOnly: true })
  @IsArray({ message: 'dictIds 必须是一个数组' })
  @ArrayNotEmpty({ message: 'dictIds 数组不能为空' })
  @IsInt({ each: true, message: 'dictIds 数组中的每个元素都必须是整数' })
  readonly dictIds: number[];
}
